package com.demo.rabbitmq.config;


import com.rabbitmq.client.AMQP;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    //交换机名称
    public static final String ITEM_TOPIC_EXCHANGE = "item_tocip_exchange";
    //列队名称
    public static final String ITEM_QUEUE = "item_queue";

    //声明交换机
    @Bean("itemTopicExchange")
    public Exchange topicExchange() {

        System.out.println("声明交换机");
        return ExchangeBuilder.topicExchange(ITEM_TOPIC_EXCHANGE).durable(true).build();
    }
    //声明列队

    @Bean("itemQueue")
    public Queue itemQueue() {
        System.out.println("itemQueue");
        return QueueBuilder.durable(ITEM_QUEUE).build();
    }

    //绑定列队和交换机
    @Bean
    public Binding itemQueueEcchange(@Qualifier("itemQueue") Queue queue, @Qualifier("itemTopicExchange") Exchange exchange) {

        System.out.println("绑定列队和交换机");
        return BindingBuilder.bind(queue).to(exchange).with("item.#").noargs();
    }

}
